<?php /*
	*/ ?>
<? 
include("system/config.inc.php");

// IF admin is not logged in then it will redirect to the adminlogin page.
if(!isset($_SESSION['adminuserid']))
{
	header("location:adminlogin.php?msg=logfirst");
	die();
}
if(isset($_REQUEST['orderid']) && ($_REQUEST['orderid'])!="")
{
 $orderid = $_REQUEST['orderid'];
 }
if(isset($_REQUEST['Submit3']) && trim($_REQUEST['Submit3']) == "Update")
{
	if(isset($_REQUEST['select']) && trim($_REQUEST['select']) != "")
	{
		
		$stid = $_REQUEST['select'];
		$stid=explode("@",$stid);
		//print_r($_SESSION);
		//echo $stid;
		//die();	
		$query = "UPDATE `tblorders` SET `intcurrentorderstatus`='".$stid[1]."' WHERE `intid`=".$stid[0];
		$sql=$obj_db->edit($query);	
		//echo $query;
		//die();
		header("location:vieworder.php?msg=chgtonext&orderid=$orderid");
		die();
	}
}
if(isset($_REQUEST['Submit32']) && trim($_REQUEST['Submit32']) == "Submit")
{
	    $orderid = $_REQUEST['orderid'];
		$title=$_REQUEST['admincomment'];
		//$desc = $_REQUEST['taxdesc'];
		$status = 1;
		
		$notifycustomer =0;
		if(isset($_SESSION['adminuserid']))
				{
					$edit=$_SESSION['adminuserid'];
				}
		$insert="INSERT INTO `tblorderstatushistory`
		( `intorderid` , `intorderstatusid` , `dtdateadded`, `intcustomernotify`, `varcomments`,`varedite`)
		VALUES ('$orderid', '$status', NOW(), '$notifycustomer', '$title','$edit')";
		
		$sql=$obj_db->insert($insert);				
		
		header("location:vieworder.php?msg=add&orderid=$orderid");
		die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ibccomputers.com::Admin</title>
<link href="css/dunt.css" rel="stylesheet" type="text/css" />
</head>


<body onload="">
<!--<script language="JavaScript1.2">mmLoadMenus();</script>-->
<form name="frb" action="" method="post">

<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td valign="top" align="center"><? include(INC."top.php");?></td>
  </tr>
  <tr valign="top">
    <td align="center"><table width="100%" border="0" cellspacing="2" cellpadding="2">
      <tr>
        <td colspan="4" class="seprtr">&nbsp;</td>
      </tr>
      <tr>
        <td height="20" colspan="4"><strong>Admin Only </strong></td>
      </tr>
      <tr>
        <td colspan="4"><table width="100%" border="0" cellpadding="2" cellspacing="2" class="border">
            <tr align="center" class="tblbg3">
              <td>Date Added </td>
              <td>Edited By</td>
              <!--<td>Customer Notified </td>-->
              <td>Status</td>
              <td>Note</td>
            </tr>
            <? 
			if(isset($_REQUEST['orderid']) && ($_REQUEST['orderid'])!="")
			{
			$cid=$_REQUEST['orderid'];
		  	$sql4 = "SELECT * FROM `tblorderstatushistory` WHERE `intorderid`='$cid' and intcustomernotify='0'";
	
			//echo $sql2;
			//die();
			
			$result4 = $obj_db->select($sql4);
			if(count($result4)>0)
			{
				for($i4=0;$i4<count($result4);$i4++)
				 { 
		  ?>
            <tr align="center" class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onmouseover="this.className='Hrhover';" onmouseout="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
              <td><? echo printdate($result4[$i4]['dtdateadded']);?></td>
              <td align="center"><? 
				$adm=$result4[$i4]['varedite'];
				$sqla="select varadminfname from tbladmin where intid='$adm'";
				$resa=$obj_db->select($sqla);
				echo $resa[0]['varadminfname'];
				?></td>
              <!--<td><?
			$custnotify=$result4[$i4]['intcustomernotify'];
			$comment=$result4[$i4]['varcomments'];
			///if(count($resultt)>0)
			{
				//for($i=0;$i<count($resultt);$i++)
				 {
			
					if($result4[$i4]['intcustomernotify']=='0')
					{
						echo "Not Notified";
					}
					else if($result4[$i4]['intcustomernotify']=='1')
					{
						echo "Notified";
					}
				}
			}
			?></td>-->
              <td><?
			
			$stid=$result4[$i4]['intorderstatusid'];
			$sqlt="select * from `tblorderstatus` where intid='$stid'";
			
			$resultt = $obj_db->select($sqlt);
			if(count($resultt)>0)
			{
				for($i=0;$i<count($resultt);$i++)
				 {
				 	echo $resultt[$i]['varstatus'];
				 }
			}
			
			
			?></td>
              <td><? $com=$result4[$i4]['varcomments'];if(strlen($com)>10)
		  {
		  	$desc=substr($com,0,10);
			echo $desc."...";
		  }
		  else{echo $com;}?></td>
            </tr>
            <?
		  		}
			}
		  ?>
        </table></td>
      </tr>
      <tr>
        <td><strong>Admin Only Area-Free Text</strong> </td>
        <td>&nbsp;</td>
        <td colspan="2"><strong>History of order </strong></td>
      </tr>
      <tr>
        <td width="258">&nbsp;</td>
        <td width="1">&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td><textarea name="admincomment" cols="40" rows="06" id="admincomment"></textarea></td>
        <td>&nbsp;</td>
        <td colspan="2"><textarea name="admincomment12" cols="40" rows="06" id="admincomment12"><?=$comment;?>
    </textarea></td>
      </tr>
      <tr>
        <td><input name="Submit32" type="submit" class="btn" id="Submit32" value="Submit"/></td>
        <td>&nbsp;</td>
        <td width="129"><select name="select" id="select">
            <option>Select Status</option>
            <?
						//$sta = $_REQUEST['status'];						
						
						$sqlt="select * from `tblorderstatus`";
						$resman = $obj_db->select($sqlt);
						if(count($resman)>0)
						{
							for($m=0;$m<count($resman);$m++)
							{								
					?>
            <option value="<?=$cid."@".$resman[$m]['intid'];?>">
            <?=$resman[$m]['varstatus'];?>
            </option>
            <?
							}
						}
					?>
        </select></td>
        <td width="125"><input name="Submit3" type="submit" class="btn" id="Submit3" value="Update" /></td>
      </tr><? }?>
    </table></td>
  </tr>
  <tr>
    <td align="center"><? include(INC."bottom.php");?></td>
  </tr>
</table>
</form>
</body>
</html>
